package com.gzyj.server.factory.jtt808.up;

import com.gzyj.data.common.VehicleIncrement;
import com.gzyj.jtt808.v2013.HeaderMsgBodyProperty;
import com.gzyj.jtt808.v2013.Package;
import com.gzyj.jtt808.v2013.enums.BusinessDataType;
import com.gzyj.jtt808.v2013.enums.JT808TerminalResult;
import com.gzyj.jtt808.v2013.protocol.JTT808_0x0102;
import com.gzyj.jtt808.v2013.protocol.JTT808_0x8001;
import com.gzyj.server.config.LogConfig;
import com.gzyj.server.factory.CommonHandler;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.stereotype.Component;

@Component
public class JTT808_0x0102_Handler implements CommonHandler {
    @Override
    public void handler(ChannelHandlerContext ctx, Package msg) throws Exception {
        JTT808_0x0102 jtt808_0x0102=(JTT808_0x0102) msg;
        JTT808_0x8001 jtt808_0x8001 = new JTT808_0x8001();

        HeaderMsgBodyProperty headerMsgBodyProperty = new HeaderMsgBodyProperty();
        headerMsgBodyProperty.setSubcontract(jtt808_0x0102.getPackageHeader().getMsgBodyProperty().isSubcontract());
        headerMsgBodyProperty.setEncryptMethod(jtt808_0x0102.getPackageHeader().getMsgBodyProperty().getEncryptMethod());
        jtt808_0x8001.getPackageHeader().setMsgBodyProperty(headerMsgBodyProperty);
        jtt808_0x8001.getPackageHeader().setTerminalPhoneNo(jtt808_0x0102.getPackageHeader().getTerminalPhoneNo());

        jtt808_0x8001.setMsgNum(jtt808_0x0102.getPackageHeader().getMsgNum());
        jtt808_0x8001.setAckMsgId(jtt808_0x0102.getPackageHeader().getMsgId());
        jtt808_0x8001.setResult(JT808TerminalResult.成功_确认);

        ctx.writeAndFlush(jtt808_0x8001.encode());
        ctx.flush();
        LogConfig.commondLog.info("808 2013版 {} 指令 解析完成", BusinessDataType.find(jtt808_0x0102.getPackageHeader().getMsgId()));
    }

    @Override
    public void handler(ChannelHandlerContext ctx, com.gzyj.jtt808.v2019.Package msg) throws Exception {

    }

    @Override
    public void handler(ChannelHandlerContext ctx, com.gzyj.jtt808.v2011.Package msg) {

    }

    @Override
    public void handler(VehicleIncrement vehicleInfo, String msg) {

    }
}
